#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <vector>
using ll = int64_t;
#define printf
const ll inf=1e9+7;
ll n,l,a,b;
std::vector<ll> v,dp,diff;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n>>l>>a>>b;
    v.resize(l+1);dp.resize(l+1,inf);diff.resize(l+2);
    for(ll i=1;i<=n;i++){
        ll s,e;
        std::cin>>s>>e;
        v[s]++,v[e]--;
        diff[e]++;
    }
    dp[0]=0;
    for(int i=2;i<=l;i+=2){
        v[i-1]+=v[i-2];
        v[i]+=v[i-1];
        for(int j=a;j<=b&&i-j*2>=0;j++){
            if(!v[i-j*2] || diff[i-j*2]==v[i-j*2-1]){
                dp[i]=std::min(dp[i],dp[i-j*2]+1);
            }
        }
        printf("now[%lld]=%lld\n",i,v[i]);
        printf("dp[%lld]=%lld\n",i,dp[i]);
        printf("diff[%lld]=%lld\n",i,diff[i]);
        printf("\n");
    }
    std::cout<<(dp[l]>=inf?-1:dp[l])<<"\n";
}